/**
 * 
 */
package tp.pr5.console;

import java.util.List;

import tp.pr5.Constants;
import tp.pr5.Direction;
import tp.pr5.NavigationObserver;
import tp.pr5.PlaceInfo;
import tp.pr5.RobotEngineObserver;
import tp.pr5.items.InventoryObserver;
import tp.pr5.items.Item;

/**
 * @author Victor y Henar
 * The view that displays the application on the System.out. It implements all the observer interfaces in order to be notified about every event that occur when the robot is running.
 */
public class Console implements NavigationObserver, RobotEngineObserver, InventoryObserver
{

	/**
	 * Default constructor
	 */
	public Console() {
	}

	@Override
	public void inventoryChange(List<Item> inventory) {}

	@Override
	public void inventoryScanned(String inventoryDescription) {
		System.out.println(Constants.MESSAGE_SAYS + Constants.MESSAGE_ITEM_IS_IN_INVENTORY);
		System.out.println(inventoryDescription);
	}

	@Override
	public void itemScanned(String description) {
		System.out.println(Constants.MESSAGE_SAYS + description + Constants.LINE_SEPARATOR);
	}
	

	@Override
	public void itemEmpty(String itemName) {
		System.out.println(Constants.MESSAGE_SAYS + Constants.MESSAGE_EMPTY + itemName);
	}

	@Override
	public void raiseError(String msg) {
		System.out.println(msg);
	}

	@Override
	public void communicationHelp(String help) {
		System.out.println(help);
	}

	@Override
	public void engineOff(boolean atShip) {
		if (atShip)
		{
			System.out.println(Constants.MESSAGE_SAYS + Constants.MESSAGE_FIN_SPACESHIP);
		}
		else
		{
			System.out.println(Constants.MESSAGE_SAYS + Constants.MESSAGE_DIE);
		}
	}

	@Override
	public void communicationCompleted() {
		System.out.println(Constants.MESSAGE_SAYS + Constants.MESSAGE_FIN_QUIT);
	}

	@Override
	public void robotUpdate(int fuel, int recycledMaterial) {
		System.out.println(Constants.MESSAGE_ROBOT_POWER + fuel);
		System.out.println(Constants.MESSAGE_ROBOT_RECYCLED_MATERIAL + recycledMaterial);
	}

	@Override
	public void robotSays(String message) {
		System.out.print(message);
	}

	@Override
	public void headingChanged(Direction newHeading) {
		System.out.println(Constants.MESSAGE_HEADING + newHeading);
	}

	@Override
	public void initNavigationModule(PlaceInfo initialPlace, Direction heading) {}

	@Override
	public void robotArrivesAtPlace(Direction heading, PlaceInfo place) {
		System.out.println(Constants.MESSAGE_SAYS + Constants.MESSAGE_MOVING + heading + Constants.LINE_SEPARATOR);
		System.out.println(place.toString());

	}

	@Override
	public void placeScanned(PlaceInfo placeDescription) {
		System.out.println(placeDescription.toString());		
	}

	@Override
	public void placeHasChanged(PlaceInfo placeDescription) {}

}
